home *** CD-ROM | disk | FTP | other *** search
HTML Component | 2003-06-18 | 10.0 KB | 424 lines |
- <PUBLIC:COMPONENT tagName=CommandButton >
- <public:defaults
- viewLinkContent
- tabStop = true
- viewMasterTab = true
- />
- <PUBLIC:ATTACH EVENT="oncontentready" ONEVENT="Main()" />
- <PUBLIC:EVENT NAME="onSelectKey" ID="MnyVwrSelectKey" />
- <PUBLIC:METHOD NAME="SetEnabled" />
- <PUBLIC:METHOD NAME="SetCaption" />
- <PRIVATE:PROPERTY NAME="IsEnabled" />
- </PUBLIC:COMPONENT>
- <!----------------------------------------------------------
- Copyright (c) 2001 Microsoft Corporation.
- All rights reserved.
-
- File: CmdBtnCls.htc
- Revised: Oct 26 2001
- --------------------------------------------------------- -->
- <HTML xmlns:mnydraw="urn:schemas-microsoft-com:vml">
- <HEAD>
- <STYLE TYPE="text/css">
- <!--
- mnydraw\:*{behavior: url(#default#VML);}
- -->
- </STYLE>
- <SCRIPT TYPE="text/jscript" LANGUAGE="JScript">
- <!--
-
- @set @debug = false;
-
- var m_fIsActive = false;
-
- //**************************************************
- function GetWidth()
- {
- var szMsgId = null;
- if(element.width)
- {
- var bWdth = parseInt(element.width);
- if(!isNaN(bWdth))
- {
- return bWdth + "pt";
- }
- else
- {
- szMsgId = "errInvalidWidth";
- }
- }
- else
- {
- szMsgId = "errInvalidWidth";
- }
- if(null != szMsgId)
- {
- var hMsg = new Message(szMsgId);
- var exception = new Exception(hMsg["nbr"],hMsg["txt"]);
- throw exception;
- }
- }
- //**************************************************
- function GetHeight()
- {
- var szMsgId = null;
- if(element.height)
- {
- var bHght = parseInt(element.height);
- if(!isNaN(bHght))
- {
- return bHght + "pt";
- }
- else
- {
- szMsgId = "errInvalidHeight";
- }
- }
- else
- {
- szMsgId = "errMissingHeight";
- }
- if(null != szMsgId)
- {
- var hMsg = new Message(szMsgId);
- var exception = new Exception(hMsg["nbr"],hMsg["txt"]);
- throw exception;
- }
- }
- //**************************************************
- function SetCaption(szCaption)
- {
- var szMsgId = null;
- if(null != szCaption)
- {
- var iTkn = szCaption.indexOf("&");
- if(iTkn != -1)
- {
- if((iTkn + 1) < szCaption.length)
- {
- var chAcclKy = szCaption.charAt(iTkn + 1);
- var rxAccl = new RegExp("&" + chAcclKy);
- var hAccl = document.createElement("SPAN");
- if(document.all.htmAccelerator)
- {
- htmCaption.removeChild(htmCaption.children[0]);
- }
- hAccl.id = "htmAccelerator";
- hAccl.style.accelerator = true;
- hAccl.style.textDecoration = "underline";
- htmCaption.innerText = "";
- htmCaption.appendChild(hAccl);
- htmCaption.onkeyup = Caption_KeyUp;
- htmAccelerator.innerText = chAcclKy;
- htmCaption.innerHTML = szCaption.replace(rxAccl,htmCaption.innerHTML);
- htmCaption.accessKey = chAcclKy.toLowerCase();
- }
- else
- {
- szMsgId = "errNoAccelCharKey";
- }
- }
- else
- {
- htmCaption.innerText = szCaption;
- htmCaption.accessKey = null;
- htmCaption.onkeyup = null;
- }
- }
- else
- {
- szMsgId = "errNullCaption";
- }
- if(null != szMsgId)
- {
- var hMsg = new Message(szMsgId);
- var exception = new Exception(hMsg["nbr"],hMsg["txt"]);
- throw exception;
- }
- }
- //**************************************************
- function GetEnabled()
- {
- if(element.enabled)
- {
- var fEnbld = new Boolean();
- fEnbld = eval(element.enabled);
- return fEnbld;
- }
- else
- {
- return true;
- }
- }
- //**************************************************
- function SetEnabled(fState)
- {
- IsEnabled = fState;
- CommandButton_StaticState();
- }
- //**************************************************
- function Main()
- {
- IsEnabled = GetEnabled();
-
- var hCmdBtn = new CommandButton();
- document.body.appendChild(hCmdBtn);
-
- CommandButton_StaticState();
-
- document.body.onselectstart = function()
- {
- return false;
- }
- document.body.oncontextmenu = function()
- {
- return false;
- }
- try
- {
- SetCaption(element.caption);
- }
- catch(exception)
- {
- if(exception instanceof Exception)
- {
- HandleException(exception.number,exception.description)
- }
- else
- {
- throw exception;
- }
- }
- }
- //**************************************************
- function CommandButton()
- {
- var hCptn = new Caption();
- var hCmdBtn = document.createElement("mnydraw:roundrect");
- var hFill = document.createElement("mnydraw:fill");
-
- hCmdBtn.id = "htmCmdBtn";
- hCmdBtn.tabIndex = "1";
- hCmdBtn.hideFocus = true;
- hCmdBtn.onfocus = CommandButton_HoverState;
- hCmdBtn.onblur = CommandButton_StaticState;
- hCmdBtn.onkeyup = CommandButton_KeyUp;
- hCmdBtn.onmouseover = CommandButton_HoverState;
- hCmdBtn.onmouseout = CommandButton_StaticState;
- hCmdBtn.onclick = CommandButton_Click;
- hCmdBtn.arcsize = "0.1";
- hCmdBtn.strokecolor = "#738ac6";
- hCmdBtn.strokeweight = "1pt";
- hCmdBtn.setAttribute("backcolor","#9ecbfd");
- hCmdBtn.setAttribute("hovercolor","#ffffff");
- hFill.type = "gradient";
- hFill.method = "linear sigma";
- hFill.angle = "180";
- hFill.setAttribute("nacolor","#009afd");
- hFill.setAttribute("backcolor","#009afd");
- hFill.setAttribute("hovercolor","#9ecbfd");
-
- try
- {
- hCmdBtn.style.width = GetWidth();
- }
- catch(exception)
- {
- if(exception instanceof Exception)
- {
- HandleException(exception.number,exception.description)
- }
- else
- {
- throw exception;
- }
- }
- try
- {
- hCmdBtn.style.height = GetHeight();
- }
- catch(exception)
- {
- if(exception instanceof Exception)
- {
- HandleException(exception.number,exception.description)
- }
- else
- {
- throw exception;
- }
- }
- if(element.tooltiptext)
- {
- hCmdBtn.title = element.tooltiptext;
- }
- hCmdBtn.appendChild(hCptn);
- hCmdBtn.appendChild(hFill);
-
- return hCmdBtn;
- }
- //**************************************************
- function Caption()
- {
- var hCptn = document.createElement("DIV");
-
- hCptn.id = "htmCaption";
- hCptn.style.position = "relative";
- hCptn.style.top = "2pt"; // Offset the button strokeweight
- hCptn.style.left = "2pt"; // to better center the caption.
- hCptn.style.fontSize = "8pt";
- hCptn.style.fontFamily = ResourceList.documentElement.selectSingleNode("properties/member[@name='Caption']/style[@name='cssFontFamily']").text;
- hCptn.style.fontWeight = "bold";
- hCptn.style.textAlign = "center";
- hCptn.style.cursor = "default";
- hCptn.setAttribute("nacolor","#6898c8");
- hCptn.setAttribute("forecolor","#000000");
- try
- {
- hCptn.style.width = GetWidth();
- }
- catch(exception)
- {
- if(exception instanceof Exception)
- {
- HandleException(exception.number,exception.description)
- }
- else
- {
- throw exception;
- }
- }
- return hCptn;
- }
- //**************************************************
- function Message(szMsgName)
- {
- var hMsg = new Object();
- var hRsrc = ResourceList.documentElement.selectSingleNode("messages/msg[@name='" + szMsgName + "']");
- hMsg["txt"] = hRsrc.text;
- hMsg["nbr"] = hRsrc.getAttribute("number");
- return hMsg;
- }
- //**************************************************
- function Exception(bNumber,
- szDescription)
- {
- this.number = bNumber;
- this.description = szDescription;
- }
- //**************************************************
- function HandleException(bNumber,
- szDescription)
- {
- /*@if(@debug)
- alert("Error: " + bNumber + "\n\n" + szDescription);
- @end @*/
- }
- //**************************************************
- function CommandButton_StaticState()
- {
- htmCmdBtn.fillcolor = htmCmdBtn.getAttribute("backcolor");
- htmCmdBtn.children[1].color2 = (IsEnabled)
- ?
- htmCmdBtn.children[1].getAttribute("backcolor")
- :
- htmCmdBtn.children[1].getAttribute("nacolor")
- ;
- htmCaption.style.color = (IsEnabled)
- ?
- htmCaption.getAttribute("forecolor")
- :
- htmCaption.getAttribute("nacolor")
- ;
- }
- //**************************************************
- function CommandButton_HoverState()
- {
- if(IsEnabled)
- {
- this.fillcolor = this.getAttribute("hovercolor");
- this.children[1].color2 = this.children[1].getAttribute("hovercolor");
- }
- }
- //**************************************************
- function CommandButton_Click()
- {
- if(!IsEnabled)
- {
- window.event.returnValue = false;
- window.event.cancelBubble = true;
- }
- }
- //**************************************************
- function CommandButton_KeyUp()
- {
- if(IsEnabled)
- {
- var hEvnt = window.event;
- if(hEvnt.keyCode == 13)
- {
- if(!m_fIsActive)
- {
- m_fIsActive = true;
- RaiseEvent();
- }
- else
- {
- m_fIsActive = false;
- }
- }
- hEvnt.returnValue = false;
- hEvnt.cancelBubble = true;
- }
- }
- //**************************************************
- function Caption_KeyUp()
- {
- if(IsEnabled)
- {
- var hEvnt = window.event;
- var szAccl = htmAccelerator.innerText.toUpperCase();
- if(hEvnt.altKey && (hEvnt.keyCode == szAccl.charCodeAt(0)))
- {
- if(!m_fIsActive)
- {
- m_fIsActive = true;
- RaiseEvent();
- }
- else
- {
- m_fIsActive = false;
- }
- }
- hEvnt.returnValue = false;
- hEvnt.cancelBubble = true;
- }
- }
- //**************************************************
- function RaiseEvent()
- {
- var hEvnt = createEventObject();
- hEvnt.result = true;
- MnyVwrSelectKey.fire (hEvnt);
- }
- //-->
- </SCRIPT>
- <XML ID="ResourceList">
- <MnyVwrRsrc xmlns="urn:schemas-microsoft.com:mnyvwr-resource">
- <properties>
- <member name="Caption">
- <style name="cssFontFamily">Tahoma</style>
- </member>
- </properties>
- <messages>
- <msg number="1" name="errInvalidWidth">Invalid value assigned to CommandButton width property.</msg>
- <msg number="2" name="errMissingWidth">No width property assigned to CommandButton.</msg>
- <msg number="3" name="errInvalidHeight">Invalid value assigned to CommandButton height property.</msg>
- <msg number="4" name="errMissingHeight">No height property assigned to CommandButton.</msg>
- <msg number="5" name="errNoAccelCharKey"><![CDATA[The & token is used in the caption, but no accelerator key is specified.]]></msg>
- <msg number="6" name="errNullCaption">Attempt to assign null value to CommandButton caption.</msg>
- </messages>
- </MnyVwrRsrc>
- </XML>
- </HEAD><BODY></BODY></HTML>
-